<html>
<head><meta charset="utf-8"><title>Shorthand notation for operand names · project-inline-asm · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/index.html">project-inline-asm</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Shorthand.20notation.20for.20operand.20names.html">Shorthand notation for operand names</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="183367131"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Shorthand%20notation%20for%20operand%20names/near/183367131" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Shorthand.20notation.20for.20operand.20names.html#183367131">(Dec 13 2019 at 15:07)</a>:</h4>
<p>In the current <code>asm!</code> proposal, you can name operands the same way you can with format strings:</p>
<div class="codehilite"><pre><span></span><span class="n">asm</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;mov {foo}, {bar}&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">foo</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">lateout</span><span class="p">(</span><span class="n">reg</span><span class="p">)</span><span class="w"> </span><span class="n">foo</span><span class="p">,</span><span class="w"> </span><span class="n">bar</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">in</span><span class="p">(</span><span class="n">reg</span><span class="p">)</span><span class="w"> </span><span class="n">bar</span><span class="p">);</span><span class="w"></span>
</pre></div>



<a name="183367224"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Shorthand%20notation%20for%20operand%20names/near/183367224" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Shorthand.20notation.20for.20operand.20names.html#183367224">(Dec 13 2019 at 15:08)</a>:</h4>
<p>Note the repetition here: <code>foo</code> and <code>bar</code> each occur 3 times in the code.</p>



<a name="183367352"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Shorthand%20notation%20for%20operand%20names/near/183367352" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Shorthand.20notation.20for.20operand.20names.html#183367352">(Dec 13 2019 at 15:09)</a>:</h4>
<p>There is an RFC to improve this for format strings (<a href="https://github.com/rust-lang/rfcs/pull/2795" target="_blank" title="https://github.com/rust-lang/rfcs/pull/2795">https://github.com/rust-lang/rfcs/pull/2795</a>):</p>
<div class="codehilite"><pre><span></span><span class="kd">let</span><span class="w"> </span><span class="n">person</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;Charlie&quot;</span><span class="p">;</span><span class="w"></span>
<span class="n">print</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;Hello, {person}!&quot;</span><span class="p">);</span><span class="w">    </span><span class="c1">// implicit named argument `person`</span>
</pre></div>



<a name="183367434"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Shorthand%20notation%20for%20operand%20names/near/183367434" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Shorthand.20notation.20for.20operand.20names.html#183367434">(Dec 13 2019 at 15:10)</a>:</h4>
<p>But this won't work for us since we need additional information apart from just the variable name (<code>in</code>/<code>out</code> &amp; register class).</p>



<a name="183370292"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Shorthand%20notation%20for%20operand%20names/near/183370292" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mark-i-m <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Shorthand.20notation.20for.20operand.20names.html#183370292">(Dec 13 2019 at 15:37)</a>:</h4>
<p>Just a thought: why not abandon positional arguments altogether? That is, the following would not only be legal, but _required_:</p>



<a name="183370352"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Shorthand%20notation%20for%20operand%20names/near/183370352" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mark-i-m <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Shorthand.20notation.20for.20operand.20names.html#183370352">(Dec 13 2019 at 15:38)</a>:</h4>
<div class="codehilite"><pre><span></span>asm!(&quot;mov {foo}, {bar}&quot;, lateout(reg) foo, in(reg) bar);
</pre></div>



<a name="183370583"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Shorthand%20notation%20for%20operand%20names/near/183370583" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mark-i-m <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Shorthand.20notation.20for.20operand.20names.html#183370583">(Dec 13 2019 at 15:40)</a>:</h4>
<p>I guess one could still use <code>{0}</code> specifiers if they really wanted positional args... but it's my experience that positional arguments are a bit of a pain in longer asm fragments because anytime you insert or remove an argument from the string, you have to count to the right place in the argument list and add or remove the right one...</p>



<a name="183373129"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Shorthand%20notation%20for%20operand%20names/near/183373129" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Shorthand.20notation.20for.20operand.20names.html#183373129">(Dec 13 2019 at 16:05)</a>:</h4>
<p>Note that in my example, <code>foo</code> and <code>bar</code> are also variable, which is why the same name is used for the operand name and the value.</p>



<a name="183373227"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Shorthand%20notation%20for%20operand%20names/near/183373227" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Shorthand.20notation.20for.20operand.20names.html#183373227">(Dec 13 2019 at 16:06)</a>:</h4>
<p>However asm operands can be arbitrary expressions:</p>
<div class="codehilite"><pre><span></span><span class="n">asm</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;mov {foo}, {bar}&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">foo</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">lateout</span><span class="p">(</span><span class="n">reg</span><span class="p">)</span><span class="w"> </span><span class="o">*</span><span class="n">some_func</span><span class="p">().</span><span class="n">val</span><span class="p">,</span><span class="w"> </span><span class="n">bar</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">in</span><span class="p">(</span><span class="n">reg</span><span class="p">)</span><span class="w"> </span><span class="mi">5</span><span class="k">i32</span><span class="p">);</span><span class="w"></span>
</pre></div>



<a name="183374582"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Shorthand%20notation%20for%20operand%20names/near/183374582" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mark-i-m <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Shorthand.20notation.20for.20operand.20names.html#183374582">(Dec 13 2019 at 16:20)</a>:</h4>
<p>Hmm... forgot about that... I don't tend to write asm fragments like that</p>



<a name="183374592"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Shorthand%20notation%20for%20operand%20names/near/183374592" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mark-i-m <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Shorthand.20notation.20for.20operand.20names.html#183374592">(Dec 13 2019 at 16:20)</a>:</h4>
<p>I'm curious how often others do?</p>



<a name="183375700"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Shorthand%20notation%20for%20operand%20names/near/183375700" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Shorthand.20notation.20for.20operand.20names.html#183375700">(Dec 13 2019 at 16:32)</a>:</h4>
<p>Here's an example from my code:</p>
<div class="codehilite"><pre><span></span><span class="w">    </span><span class="n">asm</span><span class="o">!</span><span class="p">(</span><span class="w"></span>
<span class="w">        </span><span class="n">asm_interruptible_syscall</span><span class="o">!</span><span class="p">()</span><span class="w"></span>
<span class="w">        </span>: <span class="s">&quot;=&amp;r&quot;</span><span class="w"> </span><span class="p">(</span><span class="n">interrupted</span><span class="p">)</span><span class="w"></span>
<span class="w">          </span><span class="s">&quot;={x0}&quot;</span><span class="w"> </span><span class="p">(</span><span class="n">result</span><span class="p">)</span><span class="w"></span>
<span class="w">        </span>: <span class="s">&quot;*m&quot;</span><span class="w"> </span><span class="p">(</span><span class="n">ctx</span><span class="p">.</span><span class="n">interrupt_flag</span><span class="p">)</span><span class="w"></span>
<span class="w">          </span><span class="s">&quot;{x7}&quot;</span><span class="w"> </span><span class="p">(</span><span class="n">nr</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="kt">u64</span><span class="p">)</span><span class="w"></span>
<span class="w">          </span><span class="s">&quot;{x8}&quot;</span><span class="w"> </span><span class="p">(</span><span class="n">NR_TANGO_COMPAT</span><span class="p">)</span><span class="w"></span>
<span class="w">          </span><span class="s">&quot;{x13}&quot;</span><span class="w"> </span><span class="p">(</span><span class="n">ctx</span><span class="p">.</span><span class="n">sp</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="kt">u64</span><span class="p">)</span><span class="w"></span>
<span class="w">          </span><span class="s">&quot;{x15}&quot;</span><span class="w"> </span><span class="p">(</span><span class="n">ctx</span><span class="p">.</span><span class="n">pc</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="kt">u64</span><span class="p">)</span><span class="w"></span>
<span class="w">        </span>: <span class="s">&quot;x7&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;memory&quot;</span><span class="w"></span>
<span class="w">        </span>: <span class="s">&quot;volatile&quot;</span><span class="w"></span>
<span class="w">    </span><span class="p">);</span><span class="w"></span>
</pre></div>



<a name="183495659"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Shorthand%20notation%20for%20operand%20names/near/183495659" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Shorthand.20notation.20for.20operand.20names.html#183495659">(Dec 15 2019 at 17:01)</a>:</h4>
<p>Another issue that makes this harder for us: you can <em>repeat</em> a name, if you need it to appear in more than one register. For instance, consider something like <code>in(reg) foo, inout(reg) foo</code>, which needs to supply a register containing <code>foo</code> and another register containing <code>foo</code> that you can write to to set the outgoing value of <code>foo</code>. That would make <code>{foo}</code> ambiguous.</p>



<a name="183497241"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Shorthand%20notation%20for%20operand%20names/near/183497241" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Shorthand.20notation.20for.20operand.20names.html#183497241">(Dec 15 2019 at 17:47)</a>:</h4>
<p>I'm considering not adding any shorthand notation for now. We can leave this as a future extension.</p>



<a name="183497542"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Shorthand%20notation%20for%20operand%20names/near/183497542" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Shorthand.20notation.20for.20operand.20names.html#183497542">(Dec 15 2019 at 17:56)</a>:</h4>
<p>That sounds reasonable. We can develop a shorthand in the future, after we've had some more experience with the syntax.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>